added samples
[windows-sources.git] / sdk / samples / all in on code / Visual Studio 2008 / CSADONETDataService / SchoolLinqToSQL.svc.cs
blobe9a889343f430e5e80d0d1a4b218273ddc6d5ef4
1 /****************************** Module Header ******************************\
2 * Module Name: SchoolLinqToSQL.svc.cs
3 * Project: CSADONETDataService
4 * Copyright (c) Microsoft Corporation.
5 *
6 * SchoolLinqToSQL.svc demonstrates the ADO.NET Data Service for Linq to SQL
7 * Data Classes. The Linq to SQL Data Class connects to the SQL Server
8 * database deployed by SQLServer2005DB. It contains data tables: Person,
9 * Course, CourseGrade, and CourseInstructor. The service also exports a
10 * service operation SearchCourses to let the client search course objects via
11 * SQL commands.
13 * This source is subject to the Microsoft Public License.
14 * See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL.
15 * All other rights reserved.
17 * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
18 * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
20 \***************************************************************************/
22 #region Using directive
23 using System;
24 using System.Collections.Generic;
25 using System.Data.Services;
26 using System.Linq;
27 using System.ServiceModel.Web;
28 using System.Web;
29 using CSADONETDataService.LinqToSQL;
30 #endregion
33 namespace CSADONETDataService
35 public class SchoolLinqToSQL : DataService<SchoolLinqToSQLDataContext>
37 // This method is called only once to initialize service-wide policies.
38 public static void InitializeService(IDataServiceConfiguration config)
40 // Set rules to indicate which entity sets and service operations
41 // are visible, updatable, etc.
42 config.UseVerboseErrors = true;
43 config.SetEntitySetAccessRule("*", EntitySetRights.All);
44 config.SetServiceOperationAccessRule("SearchCourses",
45 ServiceOperationRights.All);
48 /// <summary>
49 /// A service operation that searches the courses via SQL commands
50 /// and returns an IQueryable collection of Course objects
51 /// </summary>
52 /// <param name="searchText">The query SQL commands</param>
53 /// <returns>An IQueryable collection contains Course objects
54 /// </returns>
55 [WebGet]
56 public IQueryable<Course> SearchCourses(string searchText)
58 // Call DataContext.ExecuteQuery to call the search SQL commands
59 return this.CurrentDataSource.ExecuteQuery<Course>(searchText).
60 AsQueryable();